<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ctrl_connexion
 *
 * @author Rolland
 */


class ctrl_connexion {
    private $utilisateurs;
    function __construct(){
        $c = new BDDUser();
        $this->utilisateurs = $c->all();
    }
    
    public function verifierUtilisateur($login, $mdp){
        $bool = false;
        foreach ($this->utilisateurs as $u){
            if($u->getNom() == $login && $u->getPwd() == $mdp){
                $bool = true;
            }
        }
        
        return $bool;
    }
    
    public function connexion($pLogin, $pMdp){
        if($this->verifierUtilisateur($pLogin, $pMdp)){
            $_SESSION['login'] = $pLogin;
            $_SESSION['mdp'] = $pMdp;
            $entr = new BDDUser();
            $aff = new vMain();
            $i = 0;
            foreach($entr->getEntrepots() as $s){
                $lesE[$i] = array('site'=>$s->getSite(), 'id'=>$s->getId());
                $i++;
            }
            $aff->afficher($lesE);
        }
        else{
            $aff = new vAuthentification();
            $aff->afficher();
        }
    }
    
    public static function verifierConnexion(){
        $bool = false;
        if(isset($_SESSION['login'], $_SESSION['mdp'])){
            $bool = true;
        }
        
        return $bool;
    }
}

?>
